<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>Document</title>
		<link rel="stylesheet" href="../layui/css/layui.css">
		<link rel="stylesheet" type="text/css" href="../css/forget.css">
	</head>
	<body>
		<header>
			<a href="javascript:history.back(-1)" class="back"><img src="../img/back.png" height="18px"></a>
			<div class="center title">忘记密码</div>
		</header>
		<div class="register">
			<input type="text" name="phone" placeholder="手机号">
			<div class="flex">
				<input type="text" name="code" placeholder="验证码">
				<div class="getcode">获取验证码</div>
			</div>
			<input type="password" name="password" placeholder="新密码">
			<div class="w-sure"><div class="sure center">确定</div></div>
		</div>
	</body>
</html>
<script src="../js/jquery-3.3.1.js"></script>
<script src="../layui/layui.all.js"></script>
<script type="text/javascript">
	var va_code = true;
	// 发送验证码
	$('.getcode').click(function () {
		var phone=$('input[name="phone"]').val();
		var smg_code = 60;
        var code_class = $(this);
		if(phone.length<11||phone==''){
			layer.msg('请输入手机号码');
			return false;
		}
		if(va_code){
			$.post('/meiyou/sendMsg',{phone:phone,msgtype:2},function (data) {
			if (data.code==100){
				layer.msg(data.msg);
				 var time = setInterval(function(){
                            smg_code--;
                            code_class.html("重新发送("+smg_code+")");
                           
                            if(smg_code==0){
                                clearInterval(time);
                                code_class.html("重新发送");
                           
                                va_code = true;
                            }
                        },1000)
			}else{
				layer.msg(data.msg);
			}
		});
		}
	});
	$('.w-sure').click(function () {
	
	var phone=$('input[name="phone"]').val();
	var code=$('input[name="code"]').val();
	var password=$('input[name="password"]').val();
	
	if(phone==''||phone.length<11){
			layer.msg('请输入正确的手机号码');
			return false;
	}else if(code==''){
		layer.msg('请输入验证码');
		return false;
	}else if(password==''){
		layer.msg('请输入密码');
		return false;
	}
    $.get('/meiyou/updPwd',{phone:phone,mycode:code,newpwd:password},function(data){
		if(data.code==100){
          layer.msg(data.msg);
          // localStorage.setItem('uccon',phone);
          window.location.href='login.html'
         }else{
          layer.msg(data.msg);
         }
    })
});
</script>